package com.tongda.core.utils;

import java.io.IOException;

import android.content.Context;
import android.media.MediaPlayer;

/**
 * 
 * @author andy
 * 
 */
public class MediaUtil {

	public void play(Context context, int uri) {
		try {
			MediaPlayer player = MediaPlayer.create(context, uri);
			// player.setLooping(true);
			player.seekTo(0);
			// player.prepare();

			player.start();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void playSelfMessage(Context context, int raw) {
		try {
			MediaPlayer player = MediaPlayer.create(context, raw);
			player.seekTo(0);
			player.start();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void playStream() {
		MediaPlayer mediaPlayer = new MediaPlayer();
		// mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
		// mediaPlayer.setDataSource(getApplicationContext(), Uri);
		try {
			mediaPlayer.prepare();
		} catch (IllegalStateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		mediaPlayer.start();
	}
}
